<?php

namespace app\admin\controller;

use think\Controller;

use app\admin\service\UserService;
use think\validate\ValidateRule;

abstract class Base extends Controller
{
    // 请求数据
    protected $requestData = [];

    // 用户信息
    protected $userInfo = [];

    protected $token = "";

    public function __construct()
    {
        $userService = new UserService();
        parent::__construct();

        if (isset($_SERVER['HTTP_ACCESS_TOKEN'])) {
            $this->token = $_SERVER['HTTP_ACCESS_TOKEN'];
        }
        if (!$this->token) {
            jsonMsg(0, 'token不正确，请登录');
        }
        if ($_POST) {
            $input = $_POST;
        } else {
            $input = json_decode(file_get_contents('php://input'), true);
        }
//        if( empty($input) ){
//            jsonMsg(-1,'请求数据错误，请检查');
//        }
        $this->requestData = $input;
        $userInfo = $userService->detail([
            'token' => $this->token
        ]);
        if( empty($userInfo) ){
            jsonMsg(0, '用户信息不正确，请登录');
        }
        $this->userInfo = $userInfo;
    }

    /**
     * 列表
     * @return mixed
     */
    abstract function index();

    /**
     * 详情
     * @return mixed
     */
    abstract function info();

    /**
     * 增加
     * @return mixed
     */
    abstract function add();

    /**
     * 修改
     * @return mixed
     */
    abstract function edit();

    /**
     * 删除
     * @return mixed
     */
    abstract function del();

}
